<?php
defined( '_VALID_MOS' ) or die( '非法链接.' );
require_once('common.inc.php');
require_once(_INC_PATH.'database.php');
require_once(_INC_PATH.'page.inc.php');
include_once( _INC_PATH."catecae.php" );
$db = new database();
$sql = "select * from tbl_cate_sub where fcid=1 and del_flg=0 order by id";
$db->setQuery($sql);
$rows = $db->loadList();
foreach($rows as $key=>$value)
{
	$rows[$key]['sub_cor'] = getSubCor($value['id']);
	$rows[$key]['sub_photo'] = getSubPhoto($value['id']);
}
function getSubCor($ccid){
	global $db;
	$ccid = ','.$ccid.',';
	$sql = "select id,name from tbl_corporation where del_flg=0 and concat_ws(',',ccid,',') like '%".$ccid."%' order by create_time desc limit 16";
	$db->setQuery($sql);
	return $db->loadList();
}
function getSubPhoto($ccid){
	global $db;
	$sql = "select cor.id,cor.name from tbl_recom rec left join  tbl_corporation cor on cor.id=rec.recom_id where rec.type='qysy' and rec.del_flg='0' and rec.s_type='{$ccid}'";
	$db->setQuery($sql);
	$datas = $db->loadList();
	foreach($datas as $key=>$value){
		$img = findImg($value['id']);
		if(empty($img))$img = "/images/noimage.jpg";
		$datas[$key]['img'] = $img;
	}
	return $datas;
}

$smarty->assign("rows",$rows);
$pageinfo = Fetch("corporation_index.tpl");
$dir = _CORPORATION_PATH;
if(!is_dir($dir))cMkDir($dir);
writeFile($pageinfo, $dir.'index.html');
//分类下的页面
$dir = _CATEGORY_PATH;
if(!is_dir($dir))cMkDir($dir);
writeFile($pageinfo, $dir.'index.html');

echo $pageinfo;
die;